//
//  ConIdentifyViewController.m
//  Shengzhuli
//
//  Created by subook on 17/3/23.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "ConIdentifyViewController.h"
#import "ConVipViewViewController.h"
#import "GFXNetworkHandle.h"
#import "SZLAccountHelper.h"
@interface ConIdentifyViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *footView;
@property (nonatomic, retain) NSMutableDictionary *dict;
@property (nonatomic, copy) NSString *string;
@property (nonatomic, strong) UILabel *xieYiLabel;
@end

@implementation ConIdentifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //[self loadData];
    [self createLabel];
    _dict = [[NSMutableDictionary alloc] init];
    [self createFooterView];
    self.title = @"认证声明";
    // Do any additional setup after loading the view.
    [self createBaseView];
    
}
- (void)createLabel {
    _xieYiLabel = [[UILabel alloc] init];
    
    //_xieYiLabel.text = _dict[@"authentication"];
    _xieYiLabel.text = @"1、用户在享受会员服务后发布的任何内容并不反映或代表玩转地球的观点。\n2、会员类型选择后将不可以改变，请选择您最中意的会员类型。\n3、用户须对利用“玩转地球”账号或本服务传送信息的真实性、合法性、准确性、真实性等全权负责。\n4、本协议的任何条款无论因何种原因无效或不具可执行性，其余条款仍有效，对双方具有约束力。\n5、请认真阅读会员类型不同而享受的不同服务，该服务由玩转地球官方提供服务内容。\n6、审核相关用户使用中遇到的问题会在1-3个工作日解决，希望玩转地球给您带来不凡的体验。";
    _xieYiLabel.numberOfLines = 0;
    _xieYiLabel.font = [UIFont systemFontOfSize:14];
    _xieYiLabel.textColor = [UIColor lightGrayColor];
    _xieYiLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    CGSize maxSize = CGSizeMake(ScreenW-40, 9990);
    CGSize expectSize = [_xieYiLabel sizeThatFits:maxSize];
    _xieYiLabel.frame = CGRectMake(20, 20, expectSize.width, expectSize.height);
    
}
- (void)loadData {
    NSString *urlString = [PublicServer stringByAppendingString:@"/auth/app/about"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"token"] = [SZLAccountHelper shareInstance].token;
    NSLog(@"token = %@",param[@"token"]);
    [[GFXNetworkHandle shareHandle]post:urlString params:param success:^(id json) {
        _dict = json[@"result"];
        //_xieYiLabel.text = _dict[@"authentication"];
        NSLog(@"_string = %@",_string);
        
        [_tableView reloadData];
    } failure:^(NSError *error) {
        
    }];
    
}
- (void) createFooterView {
    _footView = [[UIView alloc]initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, 45))];
    UIButton *button = [[UIButton alloc] initWithFrame:_footView.frame];
    [button setTitle:@"同意并继续" forState:(UIControlStateNormal)];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button setBackgroundImage:GetImage(@"btn_bg_login_normal") forState:UIControlStateNormal];
    
    [_footView addSubview:button];
    [button addTarget:self action:@selector(agreeAndContinue) forControlEvents:(UIControlEventTouchUpInside)];
    
}
- (void)agreeAndContinue {
    
    ConVipViewViewController *vipView = [[ConVipViewViewController alloc] init];
    [self.navigationController pushViewController:vipView animated:YES];
}
- (void)createBaseView {
    _tableView =  [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH) style:(UITableViewStyleGrouped)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    _tableView.tableFooterView = _footView;
    [self.view addSubview:_tableView];
}
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.0001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *string = @"请认真阅读并遵守以下相关规定";
    return string;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return _xieYiLabel.frame.size.height+40;
    
}
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section

{
    
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    
    header.textLabel.font = [UIFont systemFontOfSize:14];
    header.textLabel.textColor = [UIColor blackColor];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
        
    }
    cell.userInteractionEnabled = NO;
    //_xieYiLabel.text =_dict[@"authentication"];
    [cell.contentView addSubview:_xieYiLabel];
    NSLog(@"_xieYiLabel =%@",_xieYiLabel.text);
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
